package com.cardvalue.sys.fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.LinearLayout;

import com.alibaba.fastjson.JSON;
import com.cardvalue.sys.R;
import com.cardvalue.sys.adapter.ApplyRecylerAdapter;
import com.cardvalue.sys.base.BaseFragment;
import com.cardvalue.sys.entity.Apply;
import com.cardvalue.sys.entity.Confirmlist;
import com.cardvalue.sys.mode.UserService;
import com.cardvalue.sys.tool.Utiltools;

import java.util.ArrayList;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;
import io.realm.Realm;
import timber.log.Timber;

/**
 * 2：融资方案  （提现按钮）
 */
public class FinancPlanFragment extends BaseFragment {
    @Bind(R.id.recyclerView)  RecyclerView mRecyclerView;
    @Bind(R.id.btn_submit) Button mSubmit;
    private ApplyRecylerAdapter applyRecylerAdapter;
    private UserService userInfo;
    private Realm realm;
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view=inflater.inflate(R.layout.activity_financplan_fragment,container, false);
        ButterKnife.bind(this,view);
        realm = Realm.getDefaultInstance();
        userInfo=new UserService(getActivity());
        //创建一个线性布局管理器,然后设置布局的方向
        LinearLayoutManager layoutManager= new LinearLayoutManager(getActivity());
        layoutManager.setOrientation(LinearLayout.VERTICAL);
        //设置布局管理器
        mRecyclerView.setLayoutManager(layoutManager);
        applyRecylerAdapter=new ApplyRecylerAdapter(getActivity());
        //  mRecyclerView.addItemDecoration(new DividerItemDecoration(getActivity(), LinearLayoutManager.VERTICAL));
        mRecyclerView.setAdapter(applyRecylerAdapter);
        userInfo.confirmlist("2",new UserService.GetConfirmlistCallback(){
            @Override
            public void success(ArrayList<Confirmlist> confirmlist) {
                Utiltools.printE("confirmlist=2222=融资方案 ==confirmlist.get(0).getItems()", JSON.toJSONString(confirmlist.get(0).getItems())+"");
                applyRecylerAdapter.update(confirmlist.get(0).getItems());


            }

            @Override
            public void fail(ArrayList<Confirmlist> confirmlist) {

            }

            @Override
            public void cancelDialog() {

            }
        });
        return view;
    }


    /**
     *点击提现 也就是更新申请（isWithdrawConfirm  1）
     */
    @OnClick(R.id.btn_submit) void click(){
        Apply apply=new Apply();
        apply.setIsWithdrawConfirm("1");
        userInfo.GetUpdateApplication(apply, new UserService.GetApplyCallback() {
            @Override
            public void success(Apply apply) {
                Timber.e("更新申请 applysucess==22222222222="+JSON.toJSONString(apply));
            }

            @Override
            public void fail(String msg) {

            }

            @Override
            public void cancelDialog() {

            }
        });
    }
}
